package S14.second;

import java.util.*;

public class F02 {
	public static void main(String[] args) {
		List<Person> list = new ArrayList<>();
        list.add(new Person("张三", 85));
        list.add(new Person("李四", 90));
        list.add(new Person("王五", 78));
        list.add(new Person("赵六", 88));
        list.add(new Person("孙七", 92));
        System.out.println("计算所有学生的总成绩：");
        int r = list.stream().reduce(0,(sum,p)->sum+p.getScore(),(s1,s2)->s1+s2);
        System.out.println(r);
        System.out.println("计算所有学生的总人数：");
        System.out.println(list.size());
        r=list.stream().reduce(0, (count, p)->++count, (s1,s2)->s1+s2);
        System.out.println(r);
        System.out.println(list.stream().count());
        r=list.parallelStream().reduce(1000, (count, p)->++count, (s1,s2)->s1+s2);
        System.out.println(r);
        System.out.println("成绩总高的学生：");
        list.stream().max((p1,p2)->p1.getScore()-p2.getScore()).ifPresent(System.out::println);
        list.stream().reduce((p1,p2)->p1.getScore()>p2.getScore()?p1:p2).ifPresent(System.out::println);
        System.out.println("有成绩大于90的学生吗？");
        System.out.println(list.stream().anyMatch(p->p.getScore()>90));
        System.out.println("所有学生成绩都大于90吗？");
        System.out.println(list.stream().allMatch(p->p.getScore()>90));
	}
}
